package com.app.coffeephilosophy.activity;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;

import com.app.coffeephilosophy.R;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class WeiboActivity extends Activity implements OnClickListener{
  
	private EditText shareContent = null;
	private Button   shareBtn = null;
	private String    content = null;
     
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.weibo);
        shareContent = (EditText)findViewById(R.id.share_content_Edit);
        shareBtn = (Button)findViewById(R.id.share_btn);
        shareBtn.setOnClickListener(this);
        
        Intent intent = getIntent();
		int imageId = intent.getIntExtra("imageId", R.drawable.lanshan_big);
      //创建保存文件
/*
        String sdCardDir = Environment.getExternalStorageDirectory()+"/cameraApp/";

            File dirFile = new File(sdCardDir);   

                   if(!dirFile.exists()){   

                       dirFile.mkdir();   

                   }  

            //创建保存文件

        File bitmapFile = new File(dirFile,"Image"+imageId+".jpg");


       BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(bitmapFile));

       Bitmap bm=Bitmap.createBitmap();
       bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);   

       bos.flush();

       bos.close();
    */
    }
  
    

	 
	public void onClick(View v) {
		
		if(v == shareBtn){
			
			content = shareContent.getText().toString();
			shareWEIBO(this, "登录", content, null);
		}
		
	}
    
	/***
	 * 
	 * @param context Activity对象
	 * @param title 标题 
	 * @param content 内容
	 * @param imageContent 图片路径
	 */
	public static void shareWEIBO(Context context,String title,String content,File imageContent){
		Intent intent=new Intent(Intent.ACTION_SEND);//该Intent设置为发送给支持ACTION_SEND的Activity
			   intent.setType("text/plain");//出现可以接收的客户端"text/html"只会出现gmail邮件客户端
			   if(null!=imageContent){
				   intent.setType("image/*");
				   intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageContent));//发送附件
			   }
			   intent.putExtra(Intent.EXTRA_SUBJECT,title);//发送标题
			   intent.putExtra(Intent.EXTRA_TEXT,content);//发送内容
		/**
		 * createChooser方法接受Intent做参数，也同时接纳了Intent里面要求的filter（ACTION_SEND)
		 * 只有支持ACTION_SEND的Activity才会被列入可选列表
		 */
		context.startActivity(Intent.createChooser(intent,"选择分享项"));  
	}
	
    
}